package java04;

import java.util.*;

interface IntegerStack {
	public Integer push(Integer item);

	public Integer pop();

	public Integer peek();

	public boolean empty();

	public int size();
}

class ArrayIntegerStack implements IntegerStack {
	private Integer[] arr;
	private int top = 0;

	public ArrayIntegerStack(Integer capacity) {

		arr = new Integer[capacity];
	}

	public String toString() {
		return Arrays.toString(arr);
	}

	public Integer push(Integer item) {

		if (item == null)
			return null;
		if (top == arr.length)
			return null;
		arr[top++] = item;
		return item;
	}

	public Integer pop() {
		if (top != 0) {
			Integer a = arr[top - 1];
			top--;
			return a;
		} else
			return null;
	}

	public Integer peek() {
		if (top != 0)
			return arr[top - 1];
		else
			return null;
	}

	public boolean empty() {
		if (top != 0)
			return false;
		else
			return true;
	}

	public int size() {
		return top;
	}
}

public class Java43 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		IntegerStack stack = new ArrayIntegerStack(n);
		int m = in.nextInt();
		for (int i = 0; i < m; i++) {
			System.out.println(stack.push(in.nextInt()));
		}
		System.out.println(stack.peek() + "," + stack.empty() + "," + stack.size());
		System.out.println(stack.toString());
		int x = in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(stack.pop());
		}
		System.out.println(stack.peek() + "," + stack.empty() + "," + stack.size());
		System.out.println(stack.toString());

	}
}